#
#  Copyright 2019 The FATE Authors. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
import argparse

from fate_flow.utils.log_utils import schedule_logger
from fate_arch import session


class SessionStop(object):
    @classmethod
    def run(cls):
        parser = argparse.ArgumentParser()
        parser.add_argument('--session', required=True, type=str, help="session manager id")
        parser.add_argument('--computing', help="computing engine", type=str)
        parser.add_argument('--federation', help="federation engine", type=str)
        parser.add_argument('--storage', help="storage engine", type=str)
        parser.add_argument('-c', '--command', required=True, type=str, help="command")
        args = parser.parse_args()
        session_id = args.session
        fate_job_id = session_id.split('_')[0]
        command = args.command
        with session.Session(session_id=session_id,
                             options={"logger": schedule_logger(fate_job_id)}) as sess:
            sess.destroy_all_sessions()


if __name__ == '__main__':
    SessionStop.run()
